package com.xhwl.logistics.strategy.context;

import com.xhwl.common.enums.vehicle.ParkSupplierEnum;
import com.xhwl.logistics.strategy.InfoSyncSupplierStrategy;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
 * @description: 同步信息到厂商实现类容器类
 * @author: lu.Aaron
 * @create: 2021-06-29 10:17
 **/
//@Component
public class InfoSyncSupplierStrategyContext {
    @Autowired
    private List<InfoSyncSupplierStrategy> list;
    private Map<Integer,InfoSyncSupplierStrategy> infoSyncSupplierStrategyMap= new ConcurrentHashMap<>();

    @PostConstruct
    public void init(){
        infoSyncSupplierStrategyMap=list.stream().collect(Collectors.toMap(InfoSyncSupplierStrategy::getParkSupplierId,i->i));
    }

    /**
     * 根据供应商id获取不同的实现类
     * @param parkSupplierEnum
     * @return
     */
    public InfoSyncSupplierStrategy getInfoSyncSupplierService(ParkSupplierEnum parkSupplierEnum){
        return  infoSyncSupplierStrategyMap.get(parkSupplierEnum.supplierId);
    }
}

